home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #1 / Amiga Plus 1999 #1.iso / System-Boost / Workbench / BackClock / sources / timer.c < prev    next >
C/C++ Source or Header  |  1998-08-10  |  1KB  |  50 lines

  1. /*****************************************************************************
  2.  *
  3.  * Nom:                timer.c
  4.  * Desc:                handle timer
  5.  *
  6.  *
  7.  * version             : $VER: timer.c 1.0 (03.02.98)
  8.  *****************************************************************************
  9.  */ 
  10.  
  11. #include <proto/exec.h>
  12. #include <devices/timer.h> 
  13. #include "utils.h"
  14. #include "timer.h" 
  15. int initTimer(idWin * prj) {
  16.   // retourne TRUE si initialisation ok  
  17.   int ret = FALSE ;
  18.   
  19.   prj->timerok = FALSE ; // ok (pour le refermer)
  20.   if ((prj->trport = CreateMsgPort()) != NULL) {
  21.     // creation port message ok
  22.     if ((prj->treq = CreateIORequest(prj->trport, sizeof(struct timerequest))) != NULL) {
  23.       // creation ioreq ok
  24.       if (!OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest*)prj->treq, 0)) {
  25.         // ouverture timer ok
  26.         ret = TRUE ;
  27.         prj->timerok = TRUE ;
  28.       }
  29.     }    
  30.   }
  31.   return ret ;
  32. }
  33. void closeTimer(idWin * prj) {
  34.   if (prj->timerok)
  35.     CloseDevice((struct IORequest*)prj->treq) ;
  36.   if (prj->treq)
  37.     DeleteIORequest(prj->treq) ;
  38.   if (prj->trport)
  39.     DeleteMsgPort(prj->trport) ;
  40. }
  41. void runtimer(idWin * prj) {
  42.   /* lance le timer
  43.    */
  44.   if (prj->timerok) {
  45.     prj->treq->tr_time.tv_secs = DEFAULT_TIME ;
  46.     prj->treq->tr_time.tv_micro = NULL ;
  47.     prj->treq->tr_node.io_Command = TR_ADDREQUEST ;
  48.     SendIO((struct IORequest *)prj->treq) ;
  49.   }
  50. }